package com.example.demo.config;

import com.example.demo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 郝文雪
 * @date 2022/8/3 18:35
 * @Description 用户登录拦截器实现
 */

@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 给当前项目添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")//拦截使用的url
                .excludePathPatterns("/user/reg")//不拦截/user/reg
                .excludePathPatterns("/user/login")//不拦截登录接口
                .excludePathPatterns("/**/*.html");//不拦截所有的html页面
    }

    /**
     * 给所有的服务添加api前缀
     * @param configurer
     */
//    @Override
//    public void configurePathMatch(PathMatchConfigurer configurer) {
//        configurer.addPathPrefix("api",c->true);
//    }
}
